<template>
  <div class="head-nav">
    <div class="nav-left">
      <svg-icon
        icon-class="menu-open"
        class="menu-open-icon"
        @click="handleOpenMenu"
      />
      <svg-icon
        v-if="goBack"
        icon-class="arrow-left"
        class="arrow-left-icon"
        @click="$global.goBack()"
      />
    </div>

    <div class="nav-center">
      <div class="nav-title" v-if="path && path != '/'">
        {{ title }}
      </div>
      <img
        class="logo-image"
        v-else
        src="@/assets/images/logo.png"
        alt=""
        srcset=""
      />
    </div>
    <van-popover
      v-model:show="languagePopover"
      trigger="click"
      placement="bottom-end"
      :actions="languageActions"
      @select="onSelect"
    >
      <template #reference>
        <svg-icon icon-class="language" class="language-icon" />
      </template>
    </van-popover>
  </div>
</template>

<script>
export default {
  data() {
    return {
      languagePopover: false,
      languageActions: [
        { text: "语言一" },
        { text: "语言二" },
        { text: "语言三" },
      ],
      path: "",
      title: "",
      goBack: false,
    };
  },
  watch: {
    $route: {
      handler(val, oldval) {
        const { meta, path } = val;
        const title = meta.title;
        const goBack = meta.goBack;
        this.title = title;
        this.path = path;
        this.goBack = goBack;
      },
      deep: true,
    },
  },
  methods: {
    handleOpenMenu() {
      this.$emit("handle-open-menu");
    },
    onSelect(e) {
      console.log(e);
    },
  },
};
</script>

<style lang="scss" scoped>
.head-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  padding: 40px 38px;
  position: relative;
  .logo-image {
    width: 180px;
    display: block;
  }
  .nav-left {
    display: flex;
    align-items: center;
  }

  .nav-title {
    font-size: 34px;
    font-weight: 700;
    color: #000;
  }
  .menu-open-icon,
  .arrow-left-icon,
  .language-icon {
    color: #000;
  }
  .arrow-left-icon {
    font-size: 40px;
    margin-left: 20px;
  }
  .menu-open-icon {
    font-size: 48px;
  }
  .language-icon {
    font-size: 64px;
  }
  .nav-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
}
</style>
